#ifndef USER_INTERACT_WINDOW_H
#define USER_INTERACT_WINDOW_H

#include <QMainWindow>
#include <QMouseEvent>
#include "socketandssl.h"
#include "Mymodbus.h"
#include <QTime>
#include <QtCharts/QPieSeries>
#include <QtCharts/qpieseries.h>
#include <QtCharts/qpieslice.h>
#include <QtCharts/qchartview.h>
#include <QtCharts/QChartGlobal>
#include <QValueAxis>
#include <QtCharts>
#include <QLineSeries>

#ifdef  __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <pthread.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <arpa/inet.h>
#include <stdbool.h>
#include <mysql/mysql.h>
#include <stdint.h>
#include <sqlite3.h>
#include <modbus/modbus.h>


#ifdef  __cplusplus
}
#endif

struct recv_From_Server_Params
{
    QWidget* send_to_target_widget;
    void* ssl_ptr;
    void* this_ptr;
};



//int recv_message_buffer_size = 1024;
static char recv_message_buffer[1024];

namespace Ui {
class user_Interact_Window;
}

class user_Interact_Window : public QMainWindow
{
    Q_OBJECT

public:
    explicit user_Interact_Window(QWidget *parent = nullptr);
    ~user_Interact_Window();

private:
    Ui::user_Interact_Window *ui;

private:
    void mousePressEvent(QMouseEvent* event) override;
    void mouseMoveEvent(QMouseEvent* event) override;

private:
    QPoint diff_pos;  // 鼠标和窗口的相对位移
    QPoint window_pos;
    QPoint mouse_pos;

public:
    static void *recv_from_server(void *ssl_ptr);

private slots:
    void on_solo_folder_pushButton_clicked();
    void on_p2p_folder_pushButton_clicked(bool checked);
    void on_solo_folder_pushButton_clicked(bool checked);
    void on_star_friends_folder_pushButton_clicked(bool checked);
    void on_my_devices_folder_pushButton_clicked(bool checked);
    void on_my_contacts_folder_pushButton_clicked(bool checked);
    void on_Quit_pushButton_clicked();
    void on_my_device_computer_checkBox_1_clicked();
    void on_backToMainWindow_pushButton_clicked();
    void on_my_device_computer_checkBox_2_clicked();
    void on_my_device_computer_checkBox_3_clicked();
    void on_send_pushButton_clicked();

    void on_add_elements_signal_recved();

    void on_exp_backToMainWindow_pushButton_clicked();

    void on_my_expriment_pushButton_clicked();

    void on_modbus_example_pushButton_clicked();

    void on_exp_backToMainWindow_pushButton_2_clicked();

    void on_start_collect_data_pushButton_clicked();

signals:
    void on_add_elements_signal_signal();

public:


private:
    QValueAxis *temperature_axisX;
    QValueAxis *temperature_axisY;
    QLineSeries *greenhouse_temperature_lineSeries;
    QLineSeries *factory_temperature_lineSeries;
    QChart *temperature_chart;
    QChartView *modbus_temperature_chartView;

    QValueAxis *humidity_axisX;
    QValueAxis *humidity_axisY;
    QLineSeries *greenhouse_humidity_lineSeries;
    QLineSeries *factory_humidity_lineSeries;
    QChart *humidity_chart;
    QChartView *modbus_humidity_chartView;

    int modbus_line_chart_count;

    bool thread_flag = true;

    SSL_CTX *ctx;

    int rc = 0;

    int client_socket;

    SSL *ssl;

    pthread_mutex_t mutex;

    modbus_t *modbus_ctx;
    int modbus_rc;
    uint16_t tab_reg[4];

    char target_IP[1024];
};

#endif // USER_INTERACT_WINDOW_H
